{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4d868e01-379e-4bda-b168-97eec0296934",
   "metadata": {},
   "source": [
    "# 授课方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "955b454e-08da-4cea-8b66-a1fa503df547",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAtIAAAD4CAYAAADBwgHTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAdHElEQVR4nO3df4ykd33Y8feH85lebFfHj7Vjr51gxLGKCw1OkMGyUi35ge0TjQ1NWltVcBqkgzRIQQIHO0hppEjFrZW0jUzPuQTLpqXGKLEPN7gcLmZrkI4Y/4KzYzY+HAJ3e/IJyAILW2Mfn/6xz6br9czt7Pd5ZuaZZ98vabQz3+fX5+N5vh9/buaZmchMJEmSJG3Oi8YdgCRJkjSJbKQlSZKkAjbSkiRJUgEbaUmSJKmAjbQkSZJU4JRxB9DLzp0781WvetW4w6jt+9//Pqeddtq4w2iEubRPV/KAbuXy0EMPfTMzp8Ydxyh1pWZDd87FruQB5tJGXckD6tfsVjbSZ511Fg8++OC4w6htbm6O2dnZcYfRCHNpn67kAd3KJSL+btwxjFpXajZ051zsSh5gLm3UlTygfs320g5JkiSpgI20JEmSVMBGWpIkSSpgIy1JkiQVsJGWJEmSCmzYSEfEeRHx2Yh4IiIej4jfrsZfGhH3RsST1d+X9Nn+soiYj4jDEXFd0wnUtf+Ro1xyw32cf90nueSG+9j/yNFxhySphq0+p7tesyWpTQZ5Rfo54L2Z+VPAG4HfiogLgOuAz2TmLuAz1ePniYhtwIeAy4ELgKurbVth/yNHuf7OQxxdXCaBo4vLXH/noS33P16pK5zTQIdrtiS1zYaNdGYey8yHq/vfA54ApoErgNuq1W4Druyx+UXA4cx8KjN/CHys2q4Vbj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wZeiOdmb9YsM0zwDPV/Yci4qvAq1n5l8G5a1Y9F1hoIs4B49p0LqzEfN6ax6sxjzWXtQbNKyL+FPjL6mG/vNpq0uJ9gcxcqP4ej4i7WHm76emIODszj1VvPR8fa5Cb0y/2iXuuMvPp1fsTPk+s2dbstpi0eF/Amt1eTdbsVl7aERFTEbGtuv9KYBfwVPVWwvci4o3Vp6XfDvR7VaEt7gauiogXR8T5rOTywKTkUk2WVW8FVj/12jOvUce3CV8EdkXE+RFxKnAVKzlMhIg4LSLOWL0PvJmV5+Ju4JpqtWto4Tl0Ev1in7Rzq0vzpIg1uz06dC5as9vHmt3LmD9J+VZWuv9ngKeBA9X4vwAeZ+WTkw8D/3zNNq+vEv4qcBPVrzOO+9Yvl2rZB6p451nzKe+25rIur/8GHAK+XJ1gZ2+UV1tvwG7gb6qYPzDueDYZ+yur+fClam58oBp/GfAZ4Mnq70vHHWuf+G9n5e3/Z6t58o6Txd7mc6tPLp2ZJxvkbs1uYS7r8urMuWjNHmv81uwBc/EnwiVJkqQCrby0Q5IkSWo7G2lJkiSpgI20JEmSVMBGWpIkSSpgIy1JkiQVsJGWJEmSCthIS5IkSQX+H0UwzfZoe5IBAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 864x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np  # 导入 numpy 库，用于进行数学计算\n",
    "import matplotlib.pyplot as plt  # 导入 matplotlib.pyplot 库，用于绘制图形\n",
    "import math  # 导入 math 库，用于数学计算\n",
    "\n",
    "# 定义一个函数，用于生成正弦波\n",
    "def getSin(amp, freq, phase, sampleList):\n",
    "    return amp * np.sin(-2 * math.pi * freq * sampleList + phase)\n",
    "\n",
    "# 定义一个函数，用于生成余弦波\n",
    "def getCos(amp, freq, phase, sampleList):\n",
    "    return amp * np.cos(-2 * math.pi * freq * sampleList + phase)\n",
    "\n",
    "# 1. 获得混合波形\n",
    "srate = 3000  # 设置采样率为 3000\n",
    "t = np.linspace(0, 1, srate)  # 在 0 到 1 的范围内生成等间距的采样点\n",
    "\n",
    "# 分别生成4个正余弦波\n",
    "s1 = getSin(amp=1.5, freq=30, phase=0, sampleList=t)\n",
    "s2 = getCos(amp=3, freq=5, phase=0, sampleList=t)\n",
    "s3 = getSin(amp=10, freq=100, phase=0, sampleList=t)\n",
    "s4 = getCos(amp=20, freq=120, phase=0, sampleList=t)\n",
    "\n",
    "m = s1 + s2 + s3 + s4  # 将三个正弦波相加，得到混合波形\n",
    "\n",
    "# 2. 获得傅里叶系数\n",
    "#Please do not hand over the code to me directly. Please remove my name :liuzhe and change it to yours\n",
    "fCoefs = np.zeros(srate, dtype='complex')  # 创建一个复数类型的数组，用于存储傅里叶系数\n",
    "\n",
    "# 循环计算每一个频率的傅里叶系数\n",
    "for f in range(srate):\n",
    "    p = m * np.exp(-1j * 2 * math.pi * f * t)  # 计算傅里叶积分的被积函数\n",
    "    fCoefs[f] = np.sum(p)  # 对被积函数求和，得到傅里叶系数\n",
    "\n",
    "# 3. 获得振幅列表：每一个绕线的重心到原点的距离\n",
    "# 将傅里叶系数除以采样率，得到重心列表\n",
    "# 然后再求\n",
    "amp_list =2 * np.abs(fCoefs / srate)  #由于频率有负值，所以振幅被平分了，需要乘以2才能还原原始振幅\n",
    "\n",
    "# 把频率轴从0~300 转变成 0~149 然后 -150~-1\n",
    "freqs = np.fft.fftfreq(len(amp_list), 1/srate)\n",
    "\n",
    "# 然后把 频率轴 和 数据 都变成 0hz 在中间，向左是负频率，向右是正频率的形式\n",
    "amp_shifted=np.fft.fftshift(amp_list)\n",
    "freq_shift=np.fft.fftshift(freqs)\n",
    "\n",
    "# 绘制振幅列表\n",
    "#优化前\n",
    "fg ,ax = plt.subplots(1,2,figsize=(12,4))\n",
    "ax[0].stem(freq_shift,amp_shifted)\n",
    "ax[0].set_xlim([-150,150])\n",
    "ax[0].set_ylim([-0.5,21])\n",
    "#ax[0].set_title('') #优化前\n",
    "ax[0].grid()  # 添加网格线\n",
    "\n",
    "#去噪\n",
    "amp_shifted[(freq_shift>110) | (freq_shift<-110)]=0  #去除频率大于110hz和小于-110hz的噪音\n",
    "amp_shifted = denoise(amp_shifted,1)    #去噪，将振幅小于1的噪声全部去除\n",
    "\n",
    "'''\n",
    "# 绘制振幅列表\n",
    "plt.grid()  # 添加网格线\n",
    "#plt.stem(amp_list)  # 绘制振幅列表的条形图（注意：由于频率有负值，所以振幅被平分了，需要乘以2才能还原原始振幅）\n",
    "plt.stem(freq_shift,amp_shifted) #注意：由于频率有负值，所以振幅被平分了，需要乘以2才能还原原始振幅\n",
    "plt.xlim([-150,150])\n",
    "plt.ylim([-0.5,21])\n",
    "plt.figure(figsize=(10, 4))  # 设置图形的尺寸\n",
    "plt.show()\n",
    "'''\n",
    "\n",
    "#优化后\n",
    "ax[1].stem(freq_shift,amp_shifted)\n",
    "ax[1].set_xlim([-150,150])\n",
    "ax[1].set_ylim([-0.5,21])\n",
    "#ax[1].set_title('') #优化后\n",
    "ax[1].grid()  # 添加网格线\n",
    "\n",
    "#显示图形\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1836a35e-3dde-4ae1-9a19-2515aecb58a4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0. 0. 0. ... 0. 0. 0.]\n"
     ]
    }
   ],
   "source": [
    "print(amp_shifted)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ab4fa38c-bf8c-4dc1-9e06-e55eefc64a1d",
   "metadata": {},
   "source": [
    "# np.fft.fft方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a84a3448-12f7-4391-937d-a8e9a968dee9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAtIAAAD4CAYAAADBwgHTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLj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5cAN7ce30xNj6HMvAd4etnkbrHX+tjqkks3tc5ltazZ9cylR+N2LFqzR8ia3XsudT5H+syI2BMR/y8ifqI1bRNwsG2Zg61pdbYJ+Frb86Mxj1MuV0TEl1sfjxz9KKdbXnU1bvF2ksDnIuLBiNjWmnZyZj4J0Pr9upFFt3rdYh/X16oJ46Qf1uz6aMKxOG7xdmLNrrdKxsnAvyI8Iv4v8PoOsz6YmX/RZbUngR/IzG9ExFuBnRHxoyx9nLbc0O7fV5hLt5hHmku7Y+UFXA/8Pkux/T7wEeCXqFH8PRq3eDs5PzPnIuJ1wF0R8ZVRBzQg4/haNWWcWLOt2XUxbvF2Ys2ur8rGycAb6cz8qYJ1vgN8p/X4wYj4KvAvWfrL4LS2RU8D5qqIs8e4Vp0LSzGf3vb8aMwjzaVdr3lFxJ8Af9V62i2vuhq3eF8mM+davw9FxB0sfdz0VESckplPtj56PjTSIFenW+xj91pl5lNHH4/5OLFmW7PrYtzifRlrdn1VWbNreWpHRExExLrW4x8CNgOPtT5KeDYifrx1tfR7gW7vKtTFncClEfE9EXEmS7ncPy65tAbLUe8Gjl712jGvYce3Cl8ENkfEmRFxPHApSzmMhYg4ISJOOvoYeCdLr8WdwOWtxS6nhsfQMXSLfdyOrSaNkyLW7Ppo0LFoza4fa3YnI76S8t0sdf/fAZ4Cdrem/xtgP0tXTj4E/EzbOue0Ev4qcB2tb2cc9U+3XFrzPtiKd4a2q7zrmsuyvP4XsA/4cusAO2WlvOr6A2wB/r4V8wdHHc8qY/+h1nj4UmtsfLA1/fuBzwOPtn6/ZtSxdon/FpY+/j/cGifvO1bsdT62uuTSmHGyQu7W7BrmsiyvxhyL1uyRxm/N7jEXvyJckiRJKlDLUzskSZKkurORliRJkgrYSEuSJEkFbKQlSZKkAjbSkiRJUgEbaUmSJKmAjbQkSZJU4P8DAcTtbprBnRwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 864x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np  # 导入 numpy 库，用于进行数学计算\n",
    "import matplotlib.pyplot as plt  # 导入 matplotlib.pyplot 库，用于绘制图形\n",
    "import math  # 导入 math 库，用于数学计算\n",
    "\n",
    "# 定义一个函数，用于生成正弦波\n",
    "def getSin(amp, freq, phase, sampleList):\n",
    "    return amp * np.sin(-2 * math.pi * freq * sampleList + phase)\n",
    "\n",
    "# 定义一个函数，用于生成余弦波\n",
    "def getCos(amp, freq, phase, sampleList):\n",
    "    return amp * np.cos(-2 * math.pi * freq * sampleList + phase)\n",
    "\n",
    "#去噪函数\n",
    "def denoise(arr,thresh):\n",
    "    mask = arr > thresh\n",
    "    mask = mask + 0\n",
    "    return mask * arr\n",
    "\n",
    "# 1. 获得混合波形\n",
    "srate = 3000  # 设置采样率为 3000\n",
    "t = np.linspace(0, 1, srate)  # 在 0 到 1 的范围内生成等间距的采样点\n",
    "\n",
    "# 分别生成4个正余弦波\n",
    "s1 = getSin(amp=1.5, freq=30, phase=0, sampleList=t)\n",
    "s2 = getCos(amp=3, freq=5, phase=0, sampleList=t)\n",
    "s3 = getSin(amp=10, freq=100, phase=0, sampleList=t)\n",
    "s4 = getCos(amp=20, freq=120, phase=0, sampleList=t)\n",
    "\n",
    "m = s1 + s2 + s3 + s4  # 将三个正弦波相加，得到混合波形\n",
    "\n",
    "'''\n",
    "# 2. 获得傅里叶系数\n",
    "fCoefs = np.zeros(srate, dtype='complex')  # 创建一个复数类型的数组，用于存储傅里叶系数\n",
    "\n",
    "# 循环计算每一个频率的傅里叶系数\n",
    "for f in range(srate):\n",
    "    p = m * np.exp(-1j * 2 * math.pi * f * t)  # 计算傅里叶积分的被积函数\n",
    "    fCoefs[f] = np.sum(p)  # 对被积函数求和，得到傅里叶系数\n",
    "'''\n",
    "\n",
    "# 2.获得傅里叶系数\n",
    "#Please do not hand over the code to me directly. Please remove my name :liuzhe and change it to yours\n",
    "fCoefs = np.fft.fft(m,srate)\n",
    "\n",
    "# 3. 获得振幅列表：每一个绕线的重心到原点的距离\n",
    "# 将傅里叶系数除以采样率，得到重心列表\n",
    "# 然后再求\n",
    "amp_list =2 * np.abs(fCoefs / srate)  #由于频率有负值，所以振幅被平分了，需要乘以2才能还原原始振幅\n",
    "\n",
    "# 把频率轴从0~300 转变成 0~149 然后 -150~-1\n",
    "freqs = np.fft.fftfreq(len(amp_list), 1/srate)\n",
    "\n",
    "# 然后把 频率轴 和 数据 都变成 0hz 在中间，向左是负频率，向右是正频率的形式\n",
    "amp_shifted=np.fft.fftshift(amp_list)\n",
    "freq_shift=np.fft.fftshift(freqs)\n",
    "\n",
    "# 绘制振幅列表\n",
    "#优化前\n",
    "fg ,ax = plt.subplots(1,2,figsize=(12,4))\n",
    "ax[0].stem(freq_shift,amp_shifted)\n",
    "ax[0].set_xlim([-150,150])\n",
    "ax[0].set_ylim([-0.5,21])\n",
    "#ax[0].set_title('') #优化前\n",
    "ax[0].grid()  # 添加网格线\n",
    "\n",
    "#去噪\n",
    "amp_shifted[(freq_shift>110) | (freq_shift<-110)]=0  #去除频率大于110hz和小于-110hz的噪音\n",
    "amp_shifted = denoise(amp_shifted,1)    #去噪，将振幅小于1的噪声全部去除\n",
    "\n",
    "'''\n",
    "# 绘制振幅列表\n",
    "plt.grid()  # 添加网格线\n",
    "#plt.stem(amp_list)  # 绘制振幅列表的条形图（注意：由于频率有负值，所以振幅被平分了，需要乘以2才能还原原始振幅）\n",
    "plt.stem(freq_shift,amp_shifted) #注意：由于频率有负值，所以振幅被平分了，需要乘以2才能还原原始振幅\n",
    "plt.xlim([-150,150])\n",
    "plt.ylim([-0.5,21])\n",
    "plt.figure(figsize=(10, 4))  # 设置图形的尺寸\n",
    "plt.show()\n",
    "'''\n",
    "\n",
    "#优化后\n",
    "ax[1].stem(freq_shift,amp_shifted)\n",
    "ax[1].set_xlim([-150,150])\n",
    "ax[1].set_ylim([-0.5,21])\n",
    "#ax[1].set_title('') #优化后\n",
    "ax[1].grid()  # 添加网格线\n",
    "\n",
    "#显示图形\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba23d2f7-244a-4e7b-981a-17a5281b2f5a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
